from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

# 创建浏览器
# 创建储存个人资料路径的变量
user_data_dir = r'--user-data-dir=C:\Users\18381\AppData\Local\Google\Chrome\User Data\Default'

# 加载配置数据
option = webdriver.ChromeOptions()
option.add_argument(user_data_dir)
driver = webdriver.Chrome(options=option)

# 访问网址
driver.get("https://mail.163.com/")
# 元素定位
# 定位写信
sleep(3)
driver.find_element(By.XPATH, "//div[@class='tx0']/ul/li[2]").click()
# 定位收件人并输入
sleep(3)
driver.find_element(By.XPATH, "//div[@class='bz0']/div/div/input").send_keys("18444110881@163.com")
# 定位主题并输入
sleep(3)
driver.find_element(By.XPATH, "//div[@class='kZ0 fu0']/div/div/div/input").send_keys("郑煬煜")
# 输入内容
sleep(3)
enter_iframe = driver.find_element(By.XPATH, "//iframe[@class='APP-editor-iframe']")
driver.switch_to.frame(enter_iframe)
driver.find_element(By.CLASS_NAME, "nui-scroll").send_keys("风萧萧兮易水寒")

# 退出当前iframe
driver.switch_to.parent_frame()
# 定位发送并点击
driver.find_element(By.XPATH, "//div[@class='nui-toolbar-item']/div/span[2]").click()
# 关闭浏览器
sleep(5)
driver.quit()
